﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace PizzaService.View
{
    /// <summary>
    /// Interaction logic for EditCustomerWindow.xaml
    /// </summary>
    public partial class EditCustomerWindow : Window
    {
        private bool m_NewCustomer;

        public EditCustomerWindow()
        {
            InitializeComponent();
            this.Loaded += EditCustomerWindow_Loaded;
        }

        /// <summary>
        /// If True a new Customer will be created
        /// </summary>
        /// <param name="newCustomer"></param>
        public EditCustomerWindow(bool newCustomer)
        {
            InitializeComponent();
            this.Loaded += EditCustomerWindow_Loaded;

            m_NewCustomer = newCustomer;
        }

        /// <summary>
        /// Startup Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void EditCustomerWindow_Loaded(object sender, RoutedEventArgs e)
        {
            DataContext = App.Controller.EditKundeViewModel;
        }

        /// <summary>
        /// OK Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnOk_Click_1(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Name) && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Vorname)
                && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Strasse) && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.PLZ)
                && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Ort) && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Mail)
                && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Hausnummer) && !String.IsNullOrEmpty(App.Controller.EditKundeViewModel.Telefonnummer))
            {
                if (m_NewCustomer)
                    App.Controller.SaveNewCustomer();
                else
                    App.Controller.SaveCustomer();

                this.Close();
            }
            else
                MessageBox.Show("Es müssen alle Felder ausgefüllt werden!");
        }
        /// <summary>
        /// Cancel Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnCancel_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
